package test.day215;

import java.io.*;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class LoginThread extends Thread {
    static List<User> users=new ArrayList<>();
    static {//静态代码块
        users.add(new User("老吴","!234"));
        users.add(new User("小李","1234"));
        users.add(new User("老张","234"));
        users.add(new User("小王","aaaa"));
    }
    private final Socket s;

    public LoginThread(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        try {
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            PrintWriter pw=new PrintWriter(out,true);
            //接受客户端发来的用户名和密码
            String yonghu=br.readLine();
            String mima=br.readLine();
            boolean enter=false;
            for (User u:users) {
                if (u.getName().equals(yonghu) && u.getPass().equals(mima)) {
                    enter = true;
                    break;
                }
            }
            if (enter)
                pw.println("登录成功");
            else
                pw.println("登录失败");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }

    }
}
